#
# -= Makefile for application =-
#
# Note:
# . "make config" must be done for initial routines.
#
# Usage:
# . Change the ROOT definition, if necessary;
#   Make it point to the root of the software tree.
#

# Destination to the root of software tree
ROOT = ../../../../../..
ROOT_PRJ = ../prj/app/demo/combo/sabbat_dual

# output file name
OUT = bloader3_3606

ifdef DUAL_CPU	
	ifdef HW_SECURE_ENABLE
		OUT_BIN = ${OUT}_hw_security
	else
		OUT_BIN = ${OUT}_dual
	endif			
else
		OUT_BIN = ${OUT}_single
endif

all :
	${MAKE} release
	${MAKE} -f Makefile.cmd all

config_single : sys_config.h compiler.def
	cp sys_config.h ${ROOT}/inc
	cp compiler.def ${ROOT}/src

path:	
	./getpath.sh

config_dual : config_single
	echo -e "\nexport DUAL_CPU=1" >> ${ROOT}/src/compiler.def
	echo "DEFS += -D_DUAL_CPU_E_" >> ${ROOT}/src/compiler.def

config_hw_security : config_dual
	echo -e "\nexport HW_SECURE_ENABLE=1" >> ${ROOT}/src/compiler.def
	echo "DEFS += -D_HW_SECURITY_E_" >> ${ROOT}/src/compiler.def

config:
	${MAKE} config_dual

clean :
	${MAKE} -f Makefile.cmd clean

new :
	${MAKE} -f Makefile.cmd new

release :
	${MAKE} -f Makefile.cmd release

# Link file
link :
	${LD} ${LDFLAGS} ${NEED} -o ${OUT}.out -Map ${OUT}.map \
	  -T lscript.ld libslot.a  -lbl libboot.a -lbl ${LIB} libstandby.a lib7zip.a liblog.a -lc -lgcc -le
	${OBJCOPY} -O binary ${OUT}.out ${OUT}.abs
ifdef _BOARD_DB_M3603_01V01_
	mv ${OUT}.abs ${OUT}.bak
	cd ../prj/tools; \
	./code_build.exe ../../obj/${OUT}.map ../../obj/${OUT}.bak ../../obj/${OUT}.abs;	
endif
	./bmerger.exe ${OUT}.abs boot.cfg 128 384
#	${OBJDUMP} -D ${OUT}.out > ${OUT}.dis
	cp ${OUT}.abs ${ROOT_PRJ}/${OUT_BIN}.abs

cleanld :
	rm -f ${OUT}.out ${OUT}.map ${OUT}.dis libbl.a

sdk_single:
	cd ${ROOT}/src/boot; \
	${MAKE} rebuild_36f_single

sdk_dual:
	cd ${ROOT}/src/boot; \
	${MAKE} rebuild_36f
	
sdk_security:
	cd ${ROOT}/src/boot; \
	${MAKE} rebuild_36f_security	
	
sdk:
	${MAKE} sdk_dual

sdk_rel:
	${MAKE} -f Makefile.cmd sdk_rel

sdk_clean :
	${MAKE} -f Makefile.cmd sdk_clean

dis:
	sde-objdump -D ${OUT}.out > ${OUT}.dis
